{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "58bcd93d-9864-4975-86fd-e0cc17f4498b",
   "metadata": {},
   "source": [
    "# Ungraded Lab - The Monty Hall Problem\n",
    "\n",
    "Welcome! In this ungraded lab you will see the counter intuitive nature of probability by studying the famous Monty Hall problem. This problem seems very trivial at first glance but it exemplifies the fact that probabilities can have behaviours you might not initially expect.\n",
    "\n",
    "Begin by importing the required libraries for the lab:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f0d7d503",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import utils2\n",
    "\n",
    "%matplotlib widget"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1eadc2ed-5cbb-4366-b421-b4d663c8d2d0",
   "metadata": {
    "tags": []
   },
   "source": [
    "### 1. Problem introduction\n",
    "\n",
    "Suppose you are in a TV show where you may win a car by playing a game. The game is very simple: you have to choose among three closed doors. One door has the car and the other two have goats.\n",
    "\n",
    "The game is played in two steps:\n",
    "\n",
    "1. The host lets you choose one among the three doors, but you do not open it yet.\n",
    "2. Then, the host (who know where the car is) choose one among the two remaining doors and open it, revealing a goat. \n",
    "\n",
    "<figure>\n",
    "<p align = 'center'>\n",
    "<img src=\"img/monty_hall_doors.svg\" width=\"300\">\n",
    "<figcaption>Monty Hall Problem - from Wikipedia</figcaption>\n",
    "</p>\n",
    "\n",
    "</figure>\n",
    "\n",
    "\n",
    "The time to choose has come and let's suppose you have chosen door number 1. Then, just before they open the door number 1, the Host - who already knows in which door the car is behind - opens door number 3, revealing a goat and leaving doors number 1 and 2 closed. The Host then asks you:\n",
    "\n",
    "**\"Would you like to switch your choice to door number 2?\"**\n",
    "\n",
    "This question seems weird, since the host knows which door is the winner, maybe he is trying to trick you into choosing poorly. What would you do? Would you change doors, or you would stick to door number 1?\n",
    "\n",
    "Since you are becoming more familiar with Probability and Statistics, you can think even further. What would give you the highest probability to win? Switching doors or keeping your choice? Does it matter?\n",
    "\n",
    "Well, you have Python in your hands, so, in this noteobok you will simulate this game and answer this question by yourself! At first, you can try the game in real time just below, and you may get some idea of what might goes on!"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7aa0cc7a-a16c-4ee1-9e6f-68057edb5cb8",
   "metadata": {},
   "source": [
    "## 2. Try the game for yourself!\n",
    "\n",
    "By running the next cell you can play the game for a while and try out different strategies. In the left panel you will get the actual game, these are the instructions to play:\n",
    "\n",
    "- To start a new game simply select one of the three available doors.\n",
    "- After you select an initial door the host will open one of the two remaining ones and it will always have a goat behind it.\n",
    "- Then you can decide if you would like to stay or switch doors.\n",
    "- If you pick the door opened by the host that game will not count.\n",
    "- If you click outside any of the three doors then the game will restart and not be counted.\n",
    "- After the prizes are shown (game has ended) click anywhere on the screen to restart the game.\n",
    "- If you want to restart the counters, run the cell again\n",
    "\n",
    "The right panel keeps track of the number of games played and the success rate for both strategies. Try it for a while and see if you can find any patterns!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9ef1ef76-5591-4712-ba12-7c277ecb5572",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "152419789de74091b827937f31f12099",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA+gAAAGQCAYAAAA9TUphAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA6kUlEQVR4nO3deVyVZf7/8fcB5OACuKCIRm5p5pIaLrmQ6ZBYLmNTaVpCVDqlfn8aU6m5gFlipo4tLqO5NJOmk6POfNM0JZ20SMuldELL3UpwKQE3EM71+6PhfD2xJCZwoa/n43H+ONe5rvt87us6oG/u+9y3wxhjBAAAAAAASpVXaRcAAAAAAAAI6AAAAAAAWIGADgAAAACABQjoAAAAAABYgIAOAAA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WJiWL1+ep5/D4dCwYcO0atUqNWvWTE6nU02bNtXatWvdfTZu3CiHw6GVK1fmGb9kyRI5HA4lJSUVWs9//vMfde3aVeXLl9dNN92kl156SS6XK9++s2bNUtOmTeV0OlWrVi0NHTrU4+cz13vvvef+TAcFBenRRx/N8/WXxx57TJUqVdKBAwd03333yd/fX4888kihtQIAANjMp7QLAC5Xr149RUVFad68eRo1apRq1apVYN+XX35Z48aNU9++ffXkk0/q5MmTeuONN3TXXXdp586dqly5ssLDw+VyubRlyxb17NlTkrR582Z5eXlp8+bN7m3t3LlTZ8+e1V133VVofaNHj9aUKVPUq1cvRUZG6ssvv1RkZKQuXrzo0e/gwYNatWqVHnroIdWrV0+pqan6y1/+os6dO+vrr7/Os18JCQkqX768Ro0apf379+uNN95QuXLl5OXlpZ9++knx8fH67LPPtGjRItWrV0/jx48v0jwU5KmnntLy5cs1bNgwNWnSRKdPn9aWLVuUnJysO+64Q2PGjFFaWpq+++47/fnPf5YkVapUSZKUnp6ut956S/3799egQYOUkZGh+fPnKzIyUtu2bVPLli093mvhwoW6ePGiBg8eLKfTqfvvv18ZGRkaP368Bg8erPDwcElShw4dJEkfffSR7r33XoWFhSkuLk5eXl5auHChunbtqs2bN6tt27aSpN27d6tbt26qXr264uPjlZ2drbi4OAUHBxe6lldi2LBhqly5suLj47Vv3z7Nnj1bR44ccf9hJT85OTnq2bOnEhMT9fDDD2v48OHKyMjQ+vXrtWfPHjVo0CDfMY8//riWLVumlStXqkePHoXW9dprr6l379565JFHlJWVpaVLl+qhhx7S+++/n2fsli1btGLFCg0ZMkT+/v56/fXX9cADD+jo0aOqVq2a7r77boWGhmrx4sW6//77PcYuXrxYDRo0UPv27QusJSUlRV26dFF2drZGjRqlihUrau7cuSpfvnyevvHx8ZowYYIiIiL09NNPu+f0888/1yeffKJy5cpJ+vkPJDExMWrTpo0SEhKUmpqq1157TZ988kmez3R2drYiIyPVqVMnTZ06VRUqVCh07gAAAKxmAAssXLjQSDKff/65OXDggPHx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VExMjDp06KDdu3dr8eLFHkcOr4WizsPlMjIydNNNN+nBBx9UixYtVKlSJW3YsEGff/65pk2b5u4XFhamZcuWKTY2Vm3atFGlSpXUq1cv9ezZUytWrND999+vHj166NChQ5ozZ46aNGmSb6guqP7KlStrzpw58vf3V8WKFdWuXTvVq1dPb731lu699141bdpUMTExql27tr7//ntt3LhRAQEB+t///V9J0oQJE7R27VqFh4dryJAhys7O1htvvKGmTZvqq6++8ni/3Nt8bdy48Yq+852VlaXf/e536tu3r/bt26dZs2apU6dO6t27d4FjoqKi9Ne//lWxsbHatm2bwsPDde7cOW3YsEFDhgzR73//+zxj+vTpo4ULFyoqKkoBAQGF3se9R48emj59urp3764BAwboxIkTmjlzpm655ZY8+1tUUVFRevDBByVJEydOvKIxzz//vP72t7+pe/fuGj58uPs2a3Xq1PGop3r16ho9erQmTJig7t27q3fv3u45bdOmjftidOXKldMrr7yimJgYde7cWf3793ffZq1u3bp65plnfrWm2267TZ07d9amTZuKPgkAAAClqeQvHA/kdflt1n4p91ZKl99mLdc//vEP06lTJ1OxYkVTsWJF07hxYzN06FCzb98+j36rV682kvLctuzJJ580ksz8+fOvqM7s7Gwzbtw4U7NmTVO+fHnTtWtXk5ycbKpVq2aeeuopd7+LFy+aP/3pTyYkJMSUL1/edOzY0SQlJeW5JVfubdbee++9K5qPuLg4I8mcPHnyqubhcpmZmea5554zLVq0MP7+/qZixYqmRYsWZtasWR79zp49awYMGGAqV65sJLlvueZyucykSZNMnTp1jNPpNK1atTLvv/++iY6O9rgt2+W3FMvPP//5T9OkSRPj4+OT55ZrO3fuNH/4wx9MtWrVjNPpNHXq1DF9+/Y1iYmJHtv497//bcLCwoyvr6+pX7++mTNnjnuuLvenP/3JOBwOk5ycXOC8GPN/8//vf//bDB482FSpUsVUqlTJPPLII+b06dMefX+5psb8fBu0MWPGmHr16ply5cqZmjVrmgcffNAcOHCg0DmZNWuWkWSeffbZQuubP3++adiwoXE6naZx48Zm4cKF+e6vpHxvo1enTh2P2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AAAAAAALENBRoh577DE5HA45HA6VK1dOwcHBuueee7RgwQK5XK5Sq2vFihXq1q2bqlWrJofDoV27dpVaLdcLG9f60qVLGjlypJo3b66KFSuqVq1aioqK0g8//FAq9VwvbFxrSYqPj1fjxo1VsWJFValSRREREdq6dWup1XOjmzlzpurWrSs/Pz+1a9dO27ZtK7T/e++9p8aNG8vPz0/NmzfXmjVrSqjSklWUeZk3b57Cw8NVpUoV92f61+axLCvqZybX0qVL5XA41KdPn+ItsJQUdV7OnDmjoUOHKiQkRE6nU40aNbouf56KOi8zZszQrbfeqvLlyys0NFTPPPOMLl68WELVlpyPP/5YvXr1Uq1ateRwOLRq1apfHbNp0ybdcccdcjqduuWWW7Ro0aJirxP/h4COEte9e3cdP35chw8f1gcffKAuXbpo+PDh6tmzp7Kzs4v1vS9dupRv+7lz59SpUye98sorxfr+Nxrb1vr8+fPasWOHxo0bpx07dmjFihXat2+fevfuXay13AhsW2tJatSokd58803t3r1bW7ZsUd26ddWtWzedPHmyWOtBXsuWLVNsbKzi4uK0Y8cOtWjRQpGRkTpx4kS+/T/99FP1799fTzzxhHbu3Kk+ffqoT58+2rNnTwlXXryKOi+bNm1S//79tXHjRiUlJSk0NFTdunXT999/X8KVF7+izk2uw4cP69lnn1V4eHgJVVqyijovWVlZuueee3T48GEtX75c+/bt07x581S7du0Srrx4FXVelixZolGjRikuLk7JycmaP3++li1bphdeeKGEKy9+586dU4sWLTRz5swr6n/o0CH16NFDXbp00a5duzRixAg9+eSTWrduXTFXCjcDlKDo6Gjz+9//Pk97YmKikWTmzZvnbjty5Ijp3bu3qVixovH39zcPPfSQSUlJ8Rg3a9YsU79+fVOuXDnTqFEj89e//tXjdUlm1qxZplevXqZChQomLi6u0PoOHTpkJJmdO3de7S7iv2xf61zbtm0zksyRI0eKvI/4WVlZ67S0NCPJbNiwocj7iN+mbdu2ZujQoe7nOTk5platWiYhISHf/n379jU9evTwaGvXrp354x//WKx1lrSizssvZWdnG39/f/P2228XV4ml5mrmJ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ua9Js3r1ak2cOLG0SwM4gg57JCcnq169etd8uxUrVrzm28RvU9prnRvOjxw5oo8++oij58WotNe6YsWKuuWWW3TLLbfozjvvVMOGDTV//nyNHj36mteE/AUFBcnb21upqake7ampqapZs2a+Y2rWrFmk/mXR1cxLrqlTp2ry5MnasGGDbr/99uIss1QUdW4OHDigw4cPq1evXu623DtI+Pj4aN++fWrQoEHxFl0CruYzExISonLlysnb29vddttttyklJUVZWVny9fUt1ppLwtXMy7hx4zRw4EA9+eSTkqTmzZvr3LlzGjx4sMaMGSMvrxv3GGZBv38DAgI4el5CbtxPH6zy0Ucfaffu3XrggQck/fyPx7Fjx3Ts2DF3n6+//lpnzpxRkyZN3H0++eQTj+188skn7tdhp9Je69xw/u2332rDhg2qVq3ab9gbFKa01zo/LpdLmZmZ12RbuDK+vr4KCwtTYmKiu83lcikxMVHt27fPd0z79u09+kvS+vXrC+xfFl3NvEjSlClTNHHiRK1du/a6PUOsqHPTuHFj7d69W7t27XI/evfu7T6D5vKzdsqyq/nMdOzYUfv37/e45eU333yjkJCQ6yKcS1c3L+fPn88TwnP/iGGMKb5iy4Ab4fev9UrzCnW48URHR5vu3bub48ePm++++85s377dvPzyy6ZSpUqmZ8+eJjs72xhjjMvlMi1btjTh4eFm+/btZuvWrSYsLMx07tzZva2VK1eacuXKmVmzZplvvvnGTJs2zXh7e5uNGze6++gKrlZpjDGnT582O3fuNKtXrzaSzNKlS83OnTvN8ePHr/EM3DhsXOusrCzTu3dvc9NNN5ldu3aZ48ePux+ZmZnFMAs3BhvX+uzZs2b06NEmKSnJHD582HzxxRcmJibGOJ1Os2fPnmKYBRRm6dKlxul0mkWLFpmvv/7aDB482FSuXNl9Bf+BAweaUaNGuft/8sknxsfHx0ydOtUkJyebuLg4U65cObN79+7S2oViUdR5mTx5svH19TXLly/3+P2VkZFRWrtQbIo6N790vV7FvajzcvToUePv72+GDRtm9u3bZ95//31To0YN89JLL5XWLhSLos5LXFyc8ff3N++++645ePCg+fDDD02DBg1M3759S2sXik1GRobZuXOn2blzp5Fkpk+fbnbu3Om+e82oUaPMwIED3f0PHjxoKlSoYJ577jmTnJxsZs6caby9vc3atWtLaxduOAR0lKjo6GgjyUgyPj4+pnr16iYiIsIsWLDA5OTkePS9VrdjupKAvnDhQnddlz+u9PZNyMvGtc69jV5+j8sDIIrGxrW+cOGCuf/++02tWrWMr6+vCQkJMb179zbbtm27JvuMonvjjTfMzTffbHx9fU3btm3NZ5995n6tc+fOJjo62qP/3//+d9OoUSPj6+trmjZtalavXl3CFZeMosxLnTp1bqh/q4r6mbnc9RrQjSn6vHz66aemXbt2xul0mvr165uXX37Z/YfT60lR5uXSpUsmPj7eNGjQwPj5+ZnQ0FAzZMgQ89NPP5V84cVs48aN+f7eyJ2P6Ohojz+U545p2bKl8fX1NfXr1zcLFy4s8bpvZA5jbvDzOAAAAAAAsADfQQcAAAAAwAIEdAAAAAAALEBABwAAAADAAgR0AAAAAAAsQEAHAAAAAMACBHQAAAAAACxAQAcAAAAAwAIEdAAAAAAALEBABwAAAADAAgR0AAAAAAAsQEAHAAAAAMACBHQAAAAAACxAQAcAAAAAwAIEdAAAAAAALEBABwAAAADAAgR0AAAAAAAsQEAHAAAAAMACBHQAAAAAACxAQAcAAAAAwAIEdAAAAAAALEBABwAAAADAAgR0AAAAAAAs8P8BCPV89H1BY7cAAAAASUVORK5CYII=",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='' width=1000.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "game = utils2.monty_hall_game()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c9c2b95-a8a7-4b1e-ab9d-1b4efc765685",
   "metadata": {},
   "source": [
    "Before going forward make sure that you played the game enough times to formulate an hypothesis. Is is better to switch doors? Is it better to stay on your initial guess? Or it simply does not make a difference?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a2bce75-2a71-452b-97da-24076ebda89c",
   "metadata": {},
   "source": [
    "## 3. Simulate the game for many iterations\n",
    "\n",
    "After playing for a while you might have come up with some hypothesis about the preferred strategy to beat this game. Now you will simulate the game for many iterations and see if the success rate varies from one strategy to the other.\n",
    "\n",
    "In order to do this, the `monty_hall` function is provided. This function takes a single argument which is a boolean that controls if you decide to switch doors or not. Take a look at the code comments if you want to understand how the implementation works. Notice that the value of `0` is used to represent a goat, while `1` represents a car:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e03c5e48-80be-404c-81af-f3bc7e9b7838",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "def monty_hall(switch):\n",
    "\n",
    "    # All doors have a goat initially\n",
    "    doors = np.array([0, 0, 0])\n",
    "\n",
    "    # Randomnly decide which door will have a car\n",
    "    winner_index = np.random.randint(0, 3)\n",
    "\n",
    "    # Place the car in the winner door\n",
    "    doors[winner_index] = 1\n",
    "\n",
    "    # Participant selects a door at random\n",
    "    choice = np.random.randint(0, 3)\n",
    "\n",
    "    # Get doors that can be opened (host cannot open the door chosen or the one with the car)\n",
    "    openable_doors = [i for i in range(3) if i not in (winner_index, choice)]\n",
    "\n",
    "    # Host opens one of the available doors at random\n",
    "    door_to_open = np.random.choice(openable_doors)\n",
    "\n",
    "    # Switch to the other available door (the one that is not the original choice or the opened one)\n",
    "    if switch:\n",
    "        choice = [i for i in range(3) if i not in (choice, door_to_open)][0]\n",
    "\n",
    "    # Return 1 if you open a door with a car, 0 otherwise\n",
    "    return doors[choice]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c56ddf67-362d-41a5-ad5a-b4a1ab7d8b11",
   "metadata": {},
   "source": [
    "You can use the function above to simulate one run of the game. However this would not be very practical, it is better to use the function to try a bunch of different runs at once and save the results. This way you can know for sure if one strategy beats the other after consistently using it.\n",
    "\n",
    "You can pass the above function to another function that lets you decide a strategy and perform simulations for 1, 10, 100 and 1000 runs. As you increase the number of runs you will see that the strategies converge to their true success rate: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "513e8cab-0183-4633-a2f6-45e7b1ca6c7f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "09de0fb297c743c7ac11e8c9ce716df4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(RadioButtons(description='Switch Doors?', index=1, options=(True, False), value=False), …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "utils2.success_rate_plot(monty_hall)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7988b153-00ee-424b-b5a0-ea5674ddfaca",
   "metadata": {},
   "source": [
    "## 4. Analytical Solution\n",
    "\n",
    "Now you are familiar with the problem and you have gotten a strong evidence that the best strategy is to **switch doors** because it will make you win about 67% of the times! \n",
    "\n",
    "You now will see it analytically! For this, first let's make some definitions. \n",
    "\n",
    "Define the events:\n",
    "\n",
    "$E_1$ = the car is behind door 1\n",
    "$E_2$ = the car is behind door 2\n",
    "$E_3$ = the car is behind door 3\n",
    "\n",
    "Or, in a more concise way: $E_i$ = the car is behind door $i$ for $i = 1,2,3$. \n",
    "\n",
    "Note that these events are **mutually exclusive**, in other words, you cannot have a car simuntaneously in two doors, because of the rules of the game. This means that,\n",
    "\n",
    "$P(E_1 \\cap E_2) = 0$, $P(E_1 \\cap E_3) = 0$ and $P(E_2 \\cap E_3) = 0$. You can say it also by writing that \n",
    "\n",
    "$$P(E_i \\cap E_j) = 0  \\text{      for } i \\neq j.$$\n",
    "\n",
    "Another fact, due to the rules of the game, is that **the car is behind one of the three doors**, so \n",
    "\n",
    "$$P(E_1 \\cup E_2 \\cup E_3) = 1.$$\n",
    "\n",
    "This is, in fact, the **sample space**, or **universe**, $\\omega$, because it is the set of all possible outcomes.\n",
    "\n",
    "Let's suppose you've chosen **door number 1**. Since there is an equal chance of the car being behind one of the three doors, we know that \n",
    "$$P(E_1) = \\frac{1}{3}.$$\n",
    "\n",
    "By the **complement rule**, we know that $P(E_1^c) = 1 - P(E_1) = 1 - \\frac{1}{3} = \\frac{2}{3}$\n",
    "\n",
    "Since the universe is given by $E_1 \\cup E_2 \\cup E_3$ (the car is behind door 1 OR door 2 OR door 3), then $E_1^c = E_2 \\cup E_3$, therefore $P(E_2 \\cup E_3) = \\frac{2}{3}$. You can have a visual idea in the image below.\n",
    "\n",
    "<figure>\n",
    "<p align = 'center'>\n",
    "<img src=\"img/monty_closed_doors.svg\" width=\"300\">\n",
    "<figcaption>Monty Hall Closed Doors - from Wikipedia</figcaption>\n",
    "</p>\n",
    "\n",
    "</figure>\n",
    "\n",
    "Now that you chose door 1, the Host then opens door 3, revealing a goat and asks you if you want to switch doors. If you don't switch, the probability of winning remains $\\frac{1}{3}$ because this is your initial choice. If you **do** switch, then, you can notice that the Host **gave you an additional information**. They showed to you that door 3 does not have a car, which means that \n",
    "\n",
    "$$P(E_3) = 0.$$\n",
    "\n",
    "Now you are mostly done, because as you know, $\\frac{2}{3} = P(E_2 \\cup E_3) = P(E_2) + P(E_3) - P(E_2 \\cap E_3)$. You already know that $P(E_2 \\cap E_3) = 0$, because they are mutually exclusive events (the car is behind in only **one** of the three doors), and the Host gave you a very importante piece of additional information: $P(E_3) = 0$. With this, you can easily conclude that:\n",
    "\n",
    "$$P(win | switch) = P(E_2) = \\frac{2}{3}.$$\n",
    "\n",
    "In other words, the probability that the car is behind door 2, **given that** it is not behind door 3 is $\\frac{2}{3} \\approx 0.67$ as you have just seen in your simulations!\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c3ed714",
   "metadata": {},
   "source": [
    "## 5 Generalized Monty Hall problem (optional)\n",
    "\n",
    "Let's consider the case where the player chooses $1$ door and the Host opens $k$ doors. Would it still be better to switch? Would it depend on $k$ or on $n$? \n",
    "\n",
    "\n",
    "## 5.1 Simulation\n",
    "\n",
    "You can simulate the problem to build your intuition. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5921075f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def generalized_monty_hall(switch, n = 3, k = 1):\n",
    "    if not (1 <= k <= n-2):\n",
    "        raise ValueError('k must be between 1 and n-2, so the Host can leave at least 1 openable door!')\n",
    "    \n",
    "    # All doors have a goat initially\n",
    "    doors = np.array([0 for _ in range(n)])\n",
    "    \n",
    "    # Decide which door will have a car\n",
    "    winner = np.random.randint(0,n)\n",
    "\n",
    "    # Place the car in the winner door\n",
    "    doors[winner] = 1.0\n",
    "    \n",
    "    # Participant selects a door at random\n",
    "    choice = np.random.randint(0,n)\n",
    "    \n",
    "    # Get doors that can be opened (host cannot open the door chosen or the one with the car)\n",
    "    openable_doors = [i for i in range(n) if i not in (winner, choice)]\n",
    "    \n",
    "    # Host open k of the available doors at random\n",
    "    door_to_open = np.random.choice(openable_doors, size = k, replace = False)\n",
    "    \n",
    "    # Switch to the other available door (the one that is not the original choice or the opened one)\n",
    "    if switch:\n",
    "        choices = [i for i in range(n) if i not in np.array(choice) and i not in np.array(door_to_open)]\n",
    "        # Player chooses another door at random\n",
    "        choice = np.random.choice(choices)\n",
    "    \n",
    "    # Return 1 if you open a door with a car, 0 otherwise\n",
    "    return doors[choice]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "730e81ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "34f29db140c9433ebf5936533dd3ed3f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(RadioButtons(description='Switch Doors?', index=1, options=(True, False), value=False), …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "utils2.success_rate_plot(generalized_monty_hall)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a7a04d06",
   "metadata": {},
   "source": [
    "## 5.2 Analytical solution\n",
    "\n",
    "This section is more advanced, you may skip it if you want to! \n",
    "\n",
    "Now, the game is:\n",
    "- There are $n$ doors, and you must choose one door.\n",
    "- Host opens $k$ doors and revealing goats.\n",
    "- You may or may not change your previously chosen door.\n",
    "\n",
    "The question is: is it always better to switch doors? Will it depend on $k$? \n",
    "\n",
    "To answer this question analyticaly, first define the following events:\n",
    "\n",
    "$$E_i = \\text{ the car is behind door i. In this case, } i = 1, \\ldots, n.$$\n",
    "\n",
    "Again, the $E_i$'s are independent from each other, because there is only $1$ car available.\n",
    "\n",
    "Note that, since the Host never opens the same door the player chose and also never opens the winning door, there is an upper bound for $k$, which is $n-2$, so $$ 0 \\leq k \\leq n-2.$$ \n",
    "\n",
    "It can be assumed two facts:\n",
    "\n",
    "- The player chooses door $1$\n",
    "- The host opens doors $2, \\ldots, k+1$\n",
    "\n",
    "This is because we can always rename the doors to get this result. For instance, if the player chooses door number $10$, we can rename it as door $1$ and door $1$ will become door $10$. This is just to avoid getting too complex on indices notations. In math terminology, it is usually said that we can do this *without loss of generality*, since it will not affect the final result. \n",
    "\n",
    "Now that there are $n$ doors, the probability that the car is behind door $1$ is $\\frac{1}{n}$, i.e.,\n",
    "$$P(E_1) = \\frac{1}{n}.$$\n",
    "\n",
    "By the complement rule, the probability that the door is **not** behind door $1$ is:\n",
    "\n",
    "$$P(E_1^c) = 1 - P(E_1) = 1 - \\frac{1}{n} = \\frac{n-1}{n}.$$\n",
    "\n",
    "Note that $$E_1^c = E_2 \\cup E_3 \\cup \\ldots \\cup E_n.$$\n",
    "\n",
    "There is a notation to simplify the right hand side equation above, we can write it as:\n",
    "\n",
    "$$\\bigcup_{i = 2}^{n} E_i.$$\n",
    "\n",
    "This works in the same fashion as a summation symbol, but the opeartion being performed is set union.\n",
    "\n",
    "So, we know that \n",
    "\n",
    "$$P\\left(\\bigcup_{i = 2}^{n} E_i\\right) = \\frac{n-1}{n}.$$\n",
    "\n",
    "Now we can answer the question: What is the probability of winning, given that we switch doors?\n",
    "\n",
    "Let's take a look on the following image:\n",
    "\n",
    "<figure>\n",
    "<p align = 'center'>\n",
    "<img src=\"img\\monty_hall_n_k.svg\" width=\"900\">\n",
    "<figcaption>Monty Hall Problem - adapted from Wikipedia</figcaption>\n",
    "</p>\n",
    "\n",
    "</figure>\n",
    "\n",
    "If the player switches to a random available door, then they must choose one of the $k+2, k+3, \\ldots, n-1, n$. Therefore, the probability of picking the car is:\n",
    "\n",
    "The probability of **not picking the car** in door $1$ $\\left(P(E_1^c) = \\frac{n-1}{n}\\right)$ times the probability of picking the car **now**, which is $\\frac{1}{n-k-1}$ because this is the number of remaining doors. \n",
    "\n",
    "So, the final probability is given by\n",
    "\n",
    "$$P(win | switch) = \\frac{n-1}{n} \\cdot \\frac{1}{n-k-1}.$$\n",
    "\n",
    "It can be rewriten in the following manner:\n",
    "\n",
    "$$P(win | switch) = \\frac{n-1}{n} \\cdot \\frac{1}{n-k-1} = \\frac{1}{n} \\cdot \\frac{n-1}{n-k-1} \\geq \\frac{1}{n} = P(E_1) = P(win | not\\ switch).$$\n",
    "\n",
    "And the equality only holds when $k = 0$. This means that the host does not open any door.\n",
    "\n",
    "Therefore, **it is always better to switch doors**. This may sound counterintuitive at first, but think that switching doors you are using the **new piece of information** that the host gave you, whereas if you choose not to switch, you will be ignoring this new information."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a22e9e1",
   "metadata": {},
   "source": [
    "**Congratulations! You have finished the ungraded lab on the Monty Hall problem!**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "edb774f4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  },
  "vscode": {
   "interpreter": {
    "hash": "56d44d6a8424451b5ce45d1ae0b0b7865dc60710e7f74571dd51dd80d7829ee9"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
